package com.king.designpatterns.hybriddesignpattern.hybriddesignpattern.specificationpattern;

import java.util.ArrayList;

/**
 * 用户操作类
 *
 * @author king
 * @date 2021-06-16 16:42
 */
public class UserProvider implements IUserProvider{

    /**
     * 用户列表
     */
    private ArrayList<User> users;

    public UserProvider(ArrayList<User> users) {
        this.users = users;
    }

    @Override
    public ArrayList<User> findUser(IUserSpecification userSpec) {
        ArrayList<User> result = new ArrayList<>();
        for (User user : users) {
            // 符合指定规格的用户
            if (userSpec.isSatisfiedBy(user)){
                result.add(user);
            }
        }
        return result;
    }
}
